from django.db import models
from db.models import BaseModel


class Friend(BaseModel):
    CONTACT_JURIDICTION = {
        (1, '仅聊天'),
        (2, '聊天、朋友圈'),
    }
    MOMENRS_JURIDICTION = {
        (1, '可以看到朋友圈'),
        (2, '不让看到朋友圈'),
    }
    user = models.ForeignKey('users.User', verbose_name='通讯录所属人', on_delete=models.CASCADE, related_name='user')
    friend = models.ForeignKey('users.User', verbose_name="联系人id", on_delete=models.CASCADE, related_name='friend')
    remarks = models.CharField(max_length=16, verbose_name='备注')
    label = models.CharField(max_length=32, verbose_name='标签')
    jurisdiction = models.SmallIntegerField(choices=CONTACT_JURIDICTION, default=1, verbose_name='联系人权限')
    moments = models.SmallIntegerField(choices=MOMENRS_JURIDICTION, default=1, verbose_name="朋友圈权限")
    isDisturb = models.BooleanField(default=False, verbose_name='是否免打扰')
    currentChatBg = models.ImageField(upload_to="", default='image/default.png', verbose_name="当前聊天背景")

    class Meta:
        db_table = 'tb_friend'
        verbose_name = '联系人'
        verbose_name_plural = verbose_name


class ChatRecord(BaseModel):
    CONTENT_TYPE = {
        (1, '文本'),
        (2, '图片'),
        (3, '视频'),
        (4, '语音')
    }

    friend = models.ForeignKey('Friend', on_delete=models.CharField, verbose_name="朋友信息")
    isRead = models.BooleanField(default=False)
    content = models.CharField(max_length=512, verbose_name='聊天内容', default="")
    contentType = models.SmallIntegerField(choices=CONTENT_TYPE, default=1, verbose_name='聊天消息类型')

    class Meta:
        db_table = 'tb_chatRecord'
        verbose_name = '聊天记录'
        verbose_name_plural = verbose_name


class FriendRequest(BaseModel):
    receiver = models.ForeignKey('users.User', verbose_name="好友请求接收者", on_delete=models.CASCADE, related_name='receiver')
    requester = models.ForeignKey('users.User', verbose_name='好友请求者', on_delete=models.CASCADE, related_name='requester')
    agree = models.BooleanField(default=False, verbose_name="是否同意")

    class Meta:
        db_table = 'tb_friendRequest'
        verbose_name = '好友请求'
        verbose_name_plural = verbose_name
